﻿using System;
using CI.Organism;

#region Simulation namespaces
using Microsoft.Robotics.Simulation.Engine;
using Microsoft.Robotics.Simulation.Physics;
using Microsoft.Robotics.PhysicalModel;

#endregion

namespace CI.MSRoboticsEnv
{
    public class Amoeba : IPhysicalEnvironment
    {
        /// <summary>
        /// Base object of the Organism in the physical environment, used to get locations, place in environment
        /// </summary>
        public object BaseObject { get; set; }

        /// <summary>
        /// Organism it is relative to
        /// </summary>
        public IOrganism Organism { get; set; }
        

        public Amoeba(ILocation location, IOrganism organism)
        {
            var dimensions = new Vector3(0.2f, 0.2f, 0.2f); // meters

            // create simple movable entity, with a single shape
            BaseObject = new SingleShapeEntity(
                new BoxShape(
                    new BoxShapeProperties(
                    1, // mass in kilograms.
                    new Pose(), // relative pose
                    dimensions)), // dimensions
                new Vector3(location.XAxis, location.YAxis, location.ZAxis));

            ((VisualEntity)BaseObject).State.MassDensity.Mass = 0;
            ((VisualEntity)BaseObject).State.MassDensity.Density = 0;

            // Name the entity. All entities must have unique names
            ((VisualEntity)BaseObject).State.Name = "Amoeba : " + organism.Guid;

            // save organism
            Organism = organism;
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public void Dispose()
        {
            ((VisualEntity)BaseObject).Dispose();
        }

        /// <summary>
        /// Bind all physical world events to SynapseIO
        /// eg "Left Bumper" to a IO synapse, "Right Drive" to a IO synapse
        /// </summary>
        public void BindSynapseIO()
        {
            return;
        }

        /// <summary>
        /// Unbind all physical world events to SynapseIO
        /// eg "Left Bumper" to a IO synapse, "Right Drive" to a IO synapse
        /// </summary>
        public void UnBindSynapseIO()
        {
            return;
        }
    }
}

